package com.xiaozhen.tcp.factory;

import com.xiaozhen.tcp.factory.operator.*;

/**
 * @author zhenweisheng
 * @date 2020/8/14 10:45
 * @description: 计算属性的一个工厂
 */
public class OperatorFactory {

    /**
     * 计算结果
     *
     * @param numberA        符前的数
     * @param numberB        符后的数
     * @param operatorSymbol 逻辑运算符
     * @return
     */
    public String operator(Double numberA, Double numberB, String operatorSymbol) {
        Operator operator = null;
        //数学运算
        if ("+".equals(operatorSymbol)) {
            operator = new AddOperator();
        } else if ("-".equals(operatorSymbol)) {
            operator = new SubOperator();
        } else if ("*".equals(operatorSymbol)) {
            operator = new MulOperator();
        } else if ("/".equals(operatorSymbol)) {
            operator = new DivOperator();
        }
        //进制转换
        if (operator != null) {
            Double calculation = operator.calculation(numberA, numberB);
            return String.valueOf(calculation);
        }
        return null;
    }
}
